//
//  BaseTableViewController.swift
//  Weibo
//
//  Created by 张文文 on 15/5/28.
//  Copyright (c) 2015年 zww. All rights reserved.
//

import UIKit
/**
1. 需要判断用户是否登录
2. 如果登录，执行正常的功能
3. 如果没有登录，需要"替换视图" -> loadView
*/
class BaseTableViewController: UITableViewController ,VisitorLoginViewDelegate{
   
    ///用户登录标记
//    var userLogin = false
    var userLogin = sharedUserAccount != nil
    
    ///访客登陆界面
    var visitorLoginView: VisitorLoginView?
 
    override func loadView() {
        
        if userLogin {
            // 调用 loadView 的父类方法，执行原有的代码
            super.loadView()
            return
        }
        //替换视图
        visitorLoginView = NSBundle.mainBundle().loadNibNamed("VisitorLoginView", owner: self, options: nil).last as? VisitorLoginView
        
        visitorLoginView?.delegate = self
        
        view = visitorLoginView
        
        
        //设置导航栏
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewregisterViewDidSelected")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewLoginViewDidSelected")
       
        
        
    }
    
    //MARK:未登录协议方法
    
    func visitorViewLoginViewDidSelected() {
        println("登陆了！")
        
        let sb = UIStoryboard(name: "OAuth", bundle: nil)
        presentViewController(sb.instantiateInitialViewController() as! UIViewController, animated: true, completion: nil)
        
    }
    
    func visitorViewregisterViewDidSelected() {
        println("注册了!")
    }

    
}
